//
//  TLMyBonusTableViewCell.m
//  WXReader
//
//  Created by huaya on 2025/9/5.
//  Copyright © 2025 Andrew. All rights reserved.
//

#import "TLMyBonusTableViewCell.h"

@interface TLMyBonusTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *titleLab;
@property (weak, nonatomic) IBOutlet UILabel *acquiredLab;
@property (weak, nonatomic) IBOutlet UILabel *expireLab;
@property (weak, nonatomic) IBOutlet UILabel *bonusNumbLab;

@end

@implementation TLMyBonusTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setModel:(TLMyBonusListModel *)model{
    if (model) {
        _model = model;
        
        self.titleLab.text = model.taskName;
        
        self.acquiredLab.hidden = NO;
        //状态:0可用1已过期2已使用
        if (model.status.intValue == 0) {
            
            self.acquiredLab.text = [NSString stringWithFormat:@"Acquired on %@",[self formatTimestampToLocalTime:model.transactionTimestamp.longLongValue]];
            self.expireLab.text = [NSString stringWithFormat:@"Expire on %@",[self formatTimestampToLocalTime:model.expireTimestamp.longLongValue]];
            
            self.bonusNumbLab.text = [NSString stringWithFormat:@"+%@ Bonus",model.amount];
            self.bonusNumbLab.textColor = [UIColor hex_9E6DFC];
            
        }else if (model.status.intValue == 1){
            
            self.acquiredLab.text = [NSString stringWithFormat:@"Acquired on %@",[self formatTimestampToLocalTime:model.transactionTimestamp.longLongValue]];
            self.expireLab.text = [NSString stringWithFormat:@"Expire on %@",[self formatTimestampToLocalTime:model.expireTimestamp.longLongValue]];
            
            self.bonusNumbLab.text = [NSString stringWithFormat:@"-%@ Bonus",model.amount];
            self.bonusNumbLab.textColor = [UIColor hex_999999];
        }else if (model.status.intValue == 2){
            
            self.acquiredLab.hidden = YES;
            
            self.expireLab.text = [NSString stringWithFormat:@"Used on %@",[self formatTimestampToLocalTime:model.transactionTimestamp.longLongValue]];
            
            self.bonusNumbLab.text = [NSString stringWithFormat:@"-%@ Bonus",model.amount];
            self.bonusNumbLab.textColor = [UIColor hex_999999];
        }
        
    }
}

- (NSString *)formatTimestampToLocalTime:(long)timestamp {
    // 1. 将秒级时间戳转换为 NSDate
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
    
    // 2. 获取手机系统的当前时区
    NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
    
    // 3. 配置日期格式化器
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"MMM d, yyyy HH:mm:ss"];
    
    // 4. 强制使用英文月份格式
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    [formatter setLocale:locale];
    
    // 5. 格式化日期并返回字符串
    NSString *dateString = [formatter stringFromDate:date];
    return dateString;
}

@end
